package kr.hkit.androidcomplete01.ch12;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewXml extends Activity {
	
	private ArrayAdapter<CharSequence> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.ch12_listview);
		
		adapter = ArrayAdapter.createFromResource(
				this, R.array.country, android.R.layout.simple_list_item_1);
		//싱글 초이스. 밑에도 초이스모드 싱글. 둘다 맞춰줘야 라디오버튼 나옴 
		ListView listView = (ListView) findViewById(R.id.list);
		listView.setAdapter(adapter);
		
		listView.setOnItemClickListener(mItemClickListener);
		
		/*listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		listView.setDivider(new ColorDrawable(Color.RED));
		listView.setDividerHeight(5);*/
		
	}

	
	AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener(){
		
		public void onItemClick(android.widget.AdapterView<?> parent, 
				android.view.View view, int position, long id) {
			StringBuilder sb = new StringBuilder();
			sb.append(parent.getCount()+ "개\t");
			sb.append(view.getId()+"=view Id\t");
			sb.append("position="+position+" id= " +id+" ");
			sb.append(adapter.getItem(position));
			Toast.makeText(ListViewXml.this, sb, Toast.LENGTH_LONG).show();
			
		};
	};
}
